package ch.usi.inf.pf2.gui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import ch.usi.inf.pf2.editor.InsertColumnAction;
import ch.usi.inf.pf2.editor.InsertRowAction;
import ch.usi.inf.pf2.gui.JSpreadSheetGUI;
import ch.usi.inf.pf2.gui.SpreadSheetTableModel;

public class InsertColumnListener implements ActionListener
{
    private JSpreadSheetGUI spreadTable;

    public InsertColumnListener(JSpreadSheetGUI spreadTable)
    {
	   this.spreadTable = spreadTable;
    }

    @Override
    public void actionPerformed(ActionEvent arg0)
    {
	   InsertColumnAction ica = new InsertColumnAction(spreadTable.getSheet(), spreadTable.getSelectedColumn());
	   spreadTable.getStack().addActionToUndoStack(ica);
	   ica.evaluate();
	   SpreadSheetTableModel tb = (SpreadSheetTableModel) spreadTable
			 .getTable().getModel();
	   tb.fireTableCellUpdated(spreadTable.getSelectedRow() + 1, spreadTable
			 .getSelectedColumn() + 1);
	   spreadTable.getSheet().setHasBeenSaved(false);
	   spreadTable.getTable().repaint();
    }

}
